#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/5/20 上午9:33
# @Author  : Huang-Bo
from typing import Type, Optional
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models


class AliCloudBaseClient:
    def __init__(self, client_class: Type, region_id: str, endpoint: Optional[str] = None):
        """
        :param client_class: 阿里云服务 SDK 的 Client 类，例如 ECS、SLB 等
        :param region_id: 地域 ID，如 'cn-hangzhou'
        :param endpoint: 云服务的 endpoint 地址
        """
        self.client_class = client_class
        self.region_id = region_id
        self.endpoint = endpoint

    def create_client(self):
        """
         创建阿里云服务客户端实例
         :return: 云服务的客户端实例
         """
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential,
            region_id=self.region_id,
        )
        if self.endpoint:
            config.endpoint = self.endpoint
        return self.client_class(config)
